/**
 * Helper class for reading in the standard packet
 * structure
 * @author - bigredshoes03
 * @date - 10/1/2009
 */
package networkcom;

import java.io.IOException;
import java.io.InputStream;

public class PacketInputStream extends InputStream{

	private InputStream in;
	public PacketInputStream(InputStream in){
		this.in = in;
	}

	public int read() throws IOException {
		return 0;
	}

	/**
	 * Reads in a standard packet
	 * @return - a Packet data structure
	 */
	public Packet readPacket(){
		byte[] data = null;
		int length;
		int type = Opcode.NULL;
		try{
			do{
				type = in.read();
				if(type<=Opcode.PASSWORD && type>=Opcode.DATA){
					length = in.read();
					data = new byte[length];
					in.read(data);
				}
			}while(type==Opcode.NULL);
		} catch (IOException e){}
		return new Packet(type,data);
	}

}
